<template>
  <view>

    <daya-clone-navbar :prop_clone_navbar="clone_navbar" :prop_is_ipx="is_ipx"/>

    <view class="container">
      <view class="font">
        <view class="logs_header">

          <view class="mrtxc" v-if="store_is_login">
            <image class="mrtxl" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/mtx.png"></image>
            <view class="mrtxr">
              <button @tap="goToPageUrl('/ymq_canyino2o/pages/sjzx/wmdd/wmdd')" class="djsq"
                      :style="'background:' + color">已登录,进入商家后台
              </button>
            </view>
          </view>

          <view class="mrtxc" v-if="!user_is_login && !store_is_login">
            <image class="mrtxl" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/mtx.png"></image>
            <view class="mrtxr">
              <button @tap="onLoginClick" class="djsq" :style="'background:' + color">点击登录</button>
            </view>
          </view>
          <block v-if="user_is_login">
            <view
                style="
								display: flex;
								flex-wrap: wrap;
								width: 100%;
								justify-content: space-between;
								padding: 0 10rpx;
							  "
            >
              <view @click.stop="goToPageUrlLogin('/ymq_canyino2o/pages/wallet/walletadd')" class="left">
                <text>余额</text>
                <text>{{ userInfo.wallet }}</text>
                <view class="btn">充值</view>
              </view>
              <view  @click.stop="goToPageUrlLogin('/ymq_canyino2o/pages/my/userinfo?showLoginManage=true')" class="logs_img">
                <image class="logs_imgs" :src="userInfo.img"></image>
                <view class="logs_name">
                  <view class="logs_name1">
                    <text style="display: block;">{{ userInfo.name }}</text>
                  </view>
                </view>
              </view>
              <view @click.stop="goToPageUrlLogin('/ymq_canyino2o/pages/integral/integral')" class="right">
                <text>积分</text>
                <text>{{ userInfo.total_score }}</text>
                <view class="btn">兑换</view>
              </view>
            </view>
            <image @click.stop="goToPageUrlLogin('/ymq_canyino2o/pages/my/userinfo?showLoginManage=true')" class="setting" src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/setting.png" mode="scaleToFill"/>
          </block>
        </view>
        <view class="logs_content">
          <view @tap="wdsc" class="content_left">
            <view class="content_left1">
              <image class="wallet_img" src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wdsc.png"></image>
            </view>
            <view class="content_integral">我的收藏</view>
          </view>
          <view @tap="wddz" class="content_left">
            <view class="content_middle">
              <image class="wallet_img" style="width: 80rpx; height: 60rpx"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wddz.png"></image>
            </view>
            <view class="content_integral">我的地址</view>
          </view>

          <view @tap="goToPageUrlLogin('/ymq_canyino2o/pages/errand/list')" class="content_left">
            <view class="content_right">
              <image style="width: 80rpx; height: 60rpx" class="wallet_img"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wddd.png"></image>
            </view>
            <view class="content_integral">跑腿订单</view>
          </view>

          <view @tap="goToPageUrlLogin('/ymq_canyino2o/pages/wddd/order')" class="content_left">
            <view class="content_right">
              <image style="width: 80rpx; height: 60rpx" class="wallet_img"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wddd.png"></image>
            </view>
            <view class="content_integral">外卖订单</view>
          </view>

        </view>
        <view>
          <!-- #ifdef MP-WEIXIN -->
          <!-- [miniprogram-to-uniapp] 公众号关注组件 仅微信小程序支持 -->
          <official-account></official-account>
          <!-- #endif -->

          <!-- #ifndef MP-WEIXIN -->
          <view class="px-4">
            <!--当前为非微信小程序环境，不支持公众号关注组件！-->
          </view>
          <!-- #endif -->

        </view>
        <view class="banner" v-if="lblist.length != 0">
          <view class="swiper-container">
            <swiper :autoplay="true" :circular="true" class="swiper" duration="500" :indicatorDots="lblist.length > 1"
                    interval="5000">
              <swiper-item :data-index="index" v-for="(item, index) in lblist" :key="item.unique">
                <image
                    @tap="jumps"
                    class="img"
                    :data-appid="item.appid"
                    :data-id="item.id"
                    :data-name="item.title"
                    :data-src="item.src"
                    :data-type="item.item"
                    :data-wb_src="item.src2"
                    :src="item.logo"
                ></image>
              </swiper-item>
            </swiper>
          </view>
        </view>
        <ad :unitId="item.src" v-for="(item, index) in dbllz" :key="index"></ad>
        <view class="logs_order">
          <view class="title">我的资产</view>
          <view @tap="wdyhq" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wdhb.png"></image>
              <view>我的红包</view>
            </view>
          </view>
          <view @tap="wdyhq" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wddjq.png"></image>
              <view>我的代金券</view>
            </view>
          </view>
          <view @tap="goToPageUrl('/ymq_canyino2o/pages/hyk/hyk')" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/pshyk.png"></image>
              <view>配送会员卡</view>
            </view>
          </view>

          <view @tap="goToPageUrlLogin('/ymq_canyino2o/pages/dayaShare/index')" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/share/logo.png"></image>
              <view>分享有礼</view>
            </view>
          </view>


        </view>
        <view class="logs_order">
          <view class="title">我的服务</view>
          <view @tap="un_dev" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/wnyx.png"
              ></image>
              <view>为你优选</view>
            </view>
          </view>
          <view @tap="un_dev" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/lqzx.png"
                     style="width: 120rpx; margin-left: 40rpx"></image>
              <view>领券中心</view>
            </view>
          </view>
          <view @tap="help" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/bzyfk.png"></image>
              <view>帮助与反馈</view>
            </view>
          </view>
          <view @tap="goToPageUrl('/uni_modules/uni-im/pages/index/index')" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                  src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/kefu.png"></image>
              <view>客服</view>
            </view>
          </view>
          <!-- <view @tap="wdsc" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image
                class="center_map"
                mode="aspectFit"
                src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/kf2.jpg"
                style="width: 120rpx; margin-left: 40rpx"
              ></image>
              <view>客服2</view>
            </view>
          </view> -->
        </view>

        <view class="logs_order">
          <view class="title">更多推荐</view>

          <view @tap="seller" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/sjxt.png"></image>
              <view>商家系统</view>
            </view>
          </view>

          <view @tap="toDownload" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/cwqs.png"></image>
              <view>成为骑手</view>
            </view>
          </view>
          <view @tap="goToPageUrlLogin('/ymq_canyino2o/pages/distribution/core')" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/cwtgs.png"></image>
              <view>成为推广师</view>
            </view>
          </view>
          <view @tap="un_open" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/fqgx.png"></image>
              <view>蜂群共享</view>
            </view>
          </view>

          <view v-if="user_is_login || store_is_login" @click="logout" class="logs_center" style="border: none">
            <view class="logs_centerimg">
              <image class="center_map" mode="aspectFit"
                     src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/tcdl.png"></image>
              <view>退出登录</view>
            </view>
          </view>

        </view>
        <view class="bottom">
          <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/bqsm.jpg" mode="scaleToFill"/>
          <text>版权说明</text>
        </view>
        <!-- <view class="logs_seller"> </view> -->
        <view class="copyright">
          <navigator :appId="system.tz_appid" class="copyright_logo" extraData="" openType="navigate" path=""
                     target="miniProgram" version="release">
            <image class="copyright_img" mode="aspectFill" :src="system.bq_logo"></image>
            <view class="copyright_text">{{ system.bq_name }}</view>
          </navigator>
          <view class="copyright_txt">{{ system.support }}</view>
        </view>
      </view>
    </view>

    <u-popup mode="bottom" :show="isShowModal" @close="onModalClose" @open="onModalOpen" :round="10">
      <view style="min-height: 500rpx;padding: 40rpx">
        <!-- <view class="tabs">
          <view :class="['tab-item', index === curIndex ? 'active' : '']" v-for="(item, index) in tabs" :key="item.value" @click="onTabClick(index)">
            {{ item.label }}
          </view>
        </view> -->
        <!--登录页面-->
        <u-form labelPosition="left" labelWidth="150" :model="loginParams" :rules="rules" ref="uForm" v-if="!isFindPsd">
          <u-form-item label="账号" prop="loginParams.name" borderBottom ref="item1">
            <u--input v-model="loginParams.user_tel" border="none" placeholder="请输入账号"></u--input>
            <text slot="right" @click="onFindPsdClick">忘记密码</text>
          </u-form-item>
          <u-form-item label="密码" prop="loginParams.password" borderBottom ref="item1">
            <u--input v-model="loginParams.user_pass" placeholder="请输入密码" type="password" border="none"></u--input>
            <text slot="right" style="background: #ffd263;color: #fff;padding: 10rpx 30rpx;border-radius: 20rpx;"
                  @click="loginClick">登录
            </text>
          </u-form-item>
        </u-form>
        <!--找回密码OR注册页面-->
        <u-form labelPosition="left" labelWidth="150" :model="loginParams" :rules="rules" ref="uForm" v-else>
          <u-form-item label="手机号" prop="loginParams.user_tel" borderBottom ref="item1">
            <u--input v-model="loginParams.user_tel" placeholder="请输入手机号" border="none"></u--input>
          </u-form-item>
          <u-form-item label="密码" prop="loginParams.user_pass" borderBottom ref="item1">
            <u--input v-model="loginParams.user_pass" type="password" placeholder="请输入密码" border="none"></u--input>
          </u-form-item>
          <u-form-item label="验证码" prop="loginParams.sms_code" borderBottom ref="item1">
            <u--input v-model="loginParams.sms_code" placeholder="请输入验证码" border="none"></u--input>
            <text slot="right" style="background: #ffd263;color: #fff;padding: 10rpx 30rpx;border-radius: 20rpx;"
                  @click="toSendMsg">发送验证码
            </text>
          </u-form-item>
          <view class="" style="display: flex;">
            <view @click="toRegister"
                  style="width: 200rpx;margin: 40rpx auto;text-align: center; background: #ffd263;color: #fff;padding: 10rpx 30rpx;border-radius: 20rpx;">
              提交
            </view>
            <view @click="toLogin"
                  style="width: 200rpx;margin: 40rpx auto;text-align: center; background: #ffd263;color: #fff;padding: 10rpx 30rpx;border-radius: 20rpx;">
              返回登录
            </view>
          </view>

        </u-form>
        <view class="register" v-if="!isFindPsd">
          <text style="padding: 20rpx 0 ;" @click="onFindPsdClick">立即注册</text>
          <!--<u-icon @click="getCid" name="weixin-fill" color="#42b983" size="60"></u-icon>-->
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>

// #ifdef APP || MP-WEIXIN || H5
import {mutations as uniIdMutations} from '@/uni_modules/uni-id-pages/common/store.js'

import uniImUtils from '@/uni_modules/uni-im/common/utils.js';
// #endif

import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';

var app = getApp();
var util = require('../../utils/util.js');
export default {
  components: {
    cardlist,
    gettel
  },
  data() {
    return {
      carte: [
        {
          img1: 'https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/personal/kefu.png',
          name: '客服与投诉',
          img2: '',
          margin: 'margin_top',
          border: 'border_bottom',
          bindtap: 'customer'
        },
        {
          img1: 'https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/personal/bangzhu.png',
          name: '帮助中心',
          img2: '',
          border: 'border_bottom',
          bindtap: 'help'
        }
      ],

      top: '-420',
      yhnum: '',

      system: {
        hygn: '',
        is_hy: '',
        is_tel: 0,
        model: '',
        is_cz: 0,
        qggn: '',
        ptgn: '',
        is_yy: '',
        is_jf: '',
        jfgn: '',
        is_mdrz: 0,
        tz_appid: '',
        bq_logo: '',
        bq_name: '',
        support: ''
      },

      fxset: {
        is_open: '',
        fx_name: ''
      },

      qdset: '',
      lblist: '',
      dbllz: '',
      zbllz: '',

      userInfo: {
        img: '',
        ishy: '',
        name: '',
        user_tel: '',
        wallet: '0',
        total_score: '0'
      },

      avatarUrl: '',
      nickName: '',

      color: '',
      is_open: '',
      curIndex: 0,
      tabs: [
        {
          value: '1',
          label: '账号登录'
        },
        {
          value: '2',
          label: '短信登录'
        }
      ],
      loginParams: {
        user_tel: '',
        user_pass: '',
        sms_code: '',
        share_user_id:0,
        deviceId: '',
      },
      isShowModal: false,
      isFindPsd: false,
      rules: {
        user_tel: {
          type: 'string',
          required: true,
          message: '请填写账号',
          trigger: ['blur', 'change']
        },
        user_pass: {
          type: 'string',
          required: true,
          message: '请填写密码',
          trigger: ['blur', 'change']
        }
      }
    };
  },
  created() {
    this.load_user_info();

    // #ifdef MP-WEIXIN
    console.log("uni.getStorageSync('openid_wx_mini')",uni.getStorageSync('openid_wx_mini'))
    if (uni.getStorageSync('openid_wx_mini')==undefined || uni.getStorageSync('openid_wx_mini')=='') {
      this.openid_get_wx_mini();
    }
    // #endif

    // #ifdef MP-TOUTIAO
    console.log("uni.getStorageSync('openid_toutiao_mini')",uni.getStorageSync('openid_toutiao_mini'))
    if (uni.getStorageSync('openid_toutiao_mini')==undefined || uni.getStorageSync('openid_toutiao_mini')=='') {
      this.openid_get_toutiao_mini();
    }
    // #endif
  },
  onLoad(t) {
    this.get_uni_cloud_im_config();

    this.user_is_login = uni.getStorageSync('user_is_login') ? true : false;
    this.store_is_login = uni.getStorageSync('store_is_login') ? true : false;

    if (t.is_show_login) {
      console.log("this.store_is_login", this.store_is_login)
      //显示登录
      if (this.store_is_login) {
        uni.showModal({
          title: '提示',
          content: '您已登录到商家身份，需要先退出商家,才能登录用户端.',
        })
      } else {
        if (this.user_is_login==false) {
          this.isShowModal = true;
        }
      }
    }

    app.globalData.setNavigationBarColor(this);
    this.appPageOnLoad(app);


    var that = this;
    var e = uni.getStorageSync('users').id;
    console.log(e);
    app.globalData.util.request({
      url: 'entry/wxapp/MyCoupons',
      cachetime: '0',
      data: {
        user_id: e
      },
      success: function (t) {
        console.log(t.data);
        that.setData({
          yhnum: t.data.length
        });
      }
    });
    app.globalData.util.request({
      url: 'entry/wxapp/system',
      cachetime: '0',
      success: function (t) {
        console.log(t);
        that.setData({
          system: t.data
        });
      }
    });
    app.globalData.util.request({
      url: 'entry/wxapp/CheckRetail',
      cachetime: '0',
      success: function (t) {
        console.log(t);
        that.setData({
          fxset: t.data
        });
      }
    });
    app.globalData.util.request({
      url: 'entry/wxapp/Signset',
      cachetime: '0',
      success: function (t) {
        console.log('签到设置', t);
        that.setData({
          qdset: t.data
        });
      }
    });
    app.globalData.util.request({
      url: 'entry/wxapp/ad',
      cachetime: '0',
      success: function (t) {
        console.log(t);
        for (var e = [], a = 0; a < t.data.length; a++) {
          if ('7' == t.data[a].type) {
            e.push(t.data[a]);
          }
        }
        console.log(e);
        that.setData({
          lblist: e
        });
      }
    });
    app.globalData.util.request({
      url: 'entry/wxapp/Llz',
      cachetime: '0',
      data: {
        type: '3,4'
      },
      success: function (t) {
        console.log(t);
        for (var e = [], a = [], n = 0; n < t.data.length; n++) {
          if (3 == t.data[n].type) {
            e.push(t.data[n]);
          }
          if (4 == t.data[n].type) {
            a.push(t.data[n]);
          }
        }
        that.setData({
          dbllz: e,
          zbllz: a
        });
      }
    });
    uni.getSystemInfo({
      success: function (t) {
        console.log(t.model);
        console.log(t.pixelRatio);
        console.log(t.windowWidth);
        console.log(t.windowHeight);
        console.log(t.language);
        console.log(t.version);
        console.log(t.platform);
        if ('android' != t.platform) {
          that.setData({
            top: '-330'
          });
        }
      }
    });
  },
  onReady: function () {
  },
  onShow: function () {
    this.user_is_login = uni.getStorageSync('user_is_login') ? true : false;
    this.store_is_login = uni.getStorageSync('store_is_login') ? true : false;


    var that = this;
    var t = uni.getStorageSync('users').id;
    var n = util
        .formatTime(new Date())
        .substring(0, 10)
        .replace(/\//g, '-');

    this.userInfo = uni.getStorageSync('users')
  },
  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
    this.load_user_info();
    setTimeout(()=>{
      uni.stopPullDownRefresh()
    },1000)
  },
  onReachBottom: function () {
  },
  methods: {
    get_uni_cloud_im_config() {
      //请求 uni_cloud_im_config 接口
      app.globalData.util.request({
        url: 'entry/wxapp/uni_cloud_im_config',
        success: function (res) {
          console.log("UNIAPP云配置", res)
          if (res.data.code == 1) {
            uni.setStorageSync('client_uniapp_id', res.data.data.client_uniapp_id)
            uni.setStorageSync('runner_uniapp_id', res.data.data.runner_uniapp_id)

            console.log("client_uniapp_id", uni.getStorageSync('client_uniapp_id'))
            console.log("runner_uniapp_id", uni.getStorageSync('runner_uniapp_id'))
          }
        }
      })
    },
    load_user_info() {
      //加载用户信息
      this.userInfo = uni.getStorageSync('users')
      this.user_is_login = uni.getStorageSync('user_is_login') ? true : false;
      if (this.user_is_login == false) {
        return
      }
      app.globalData.util.request({
        url: 'entry/wxapp/get_user_info',
        data: {},
        success: async (res) => {
          console.log("实时读取用户信息",res.data)
          if (res.data.code == 1) {
            uni.setStorageSync('users', res.data.data)
            this.userInfo = res.data.data
          }
        }
      });
    },
    logout() {
      //退出用户身份
      this.userInfo = null
      app.globalData.token = null
      uni.removeStorageSync('dy-token')
      this.user_is_login = false
      uni.removeStorageSync('users')
      uni.removeStorageSync('user_is_login')

      //退出商家身份
      this.store_is_login = false
      uni.removeStorageSync('store_is_login')
      uni.removeStorageSync('sjdsjid')

      // #ifdef APP || MP-WEIXIN || H5
      //退出uni-id身份
      uniIdMutations.logout()
      // #endif

      uni.$u.toast("退出成功");
      //     未登录,跳转到登录页面
      uni.reLaunch({
        url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
        fail: () => {
          uni.switchTab({
            url: '/ymq_canyino2o/pages/my2/index?is_show_login=1'
          })
        }
      })


    },
    un_open() {
      this.show95Modal("平台未开放功能");
    },
    un_dev() {
      this.show95Modal("平台未开放功能");
    },
    getCid() {
      uni.getPushClientId({
        success(res) {
          console.log('getPushClientId OK', res);
        },
        fail(e) {
          console.log('getPushClientId ERROR', e);
        }
      })
    },
    openid_get_wx_mini() {
      console.log("头条身份获取 openid_wx_mini")
      uni.login({
        success(res) {
          app.globalData.util.request({
            url: "entry/wxapp/openid",
            no_token: true,
            data: {
              code: res.code
            },
            cachetime: 0,
            success: function (res_openid) {
              console.info("openid_wx_mini", res_openid.data.openid);
              uni.setStorageSync("openid_wx_mini", res_openid.data.openid);
            },
            fail: function (err) {
              console.error("uni.login 后端服务器错误",err)
              uni.showToast({
                title: '微信身份获取 失败,不能登录!',
                icon: 'none'
              })
            }
          });
        },
        fail(err) {
          console.error("uni.login err",err)
          uni.showToast({
            title: '微信身份获取 失败,不能登录!',
            icon: 'none'
          })
        },
      });
    },
    openid_get_toutiao_mini() {
      console.log("头条身份获取 openid_get_toutiao_mini")
      uni.login({
        success(res) {
          app.globalData.util.request({
            url: "entry/wxapp/openid_toutiao",
            no_token: true,
            data: {
              code: res.code
            },
            cachetime: 0,
            success: function (res_openid) {
              console.info("openid_toutiao_mini", res_openid.data.openid);
              uni.setStorageSync("openid_toutiao_mini", res_openid.data.openid);
            },
            fail: function (err) {
              console.error("uni.login 后端服务器错误",err)
              uni.showToast({
                title: '头条身份获取 失败,不能登录!',
                icon: 'none'
              })
            }
          });
        },
        fail(err) {
          console.error("uni.login err",err)
          uni.showToast({
            title: '头条身份获取 失败,不能登录!',
            icon: 'none'
          })
        },
      });
    },
    async loginClick() {
      if (this.store_is_login) {
        //用户登录成功了,则提示请先退出用户身份,再登录商家
        uni.showToast({
          title: '请先退出商家身份,再登录用户身份!',
          icon: 'none'
        })
        return
      }

      this.loginParams.deviceId = uni.getSystemInfoSync().deviceId
      app.globalData.util.request({
        url: 'entry/wxapp/login_tel',
        no_token: true,
        data: {
          ...this.loginParams
        },
        success: async (res) => {
          uni.showToast({
            title: res.data.msg
          });
          if (res.data.code != 0) {
            this.isShowModal = false
            this.userInfo = res.data.data.user

            //全局用户信息
            app.globalData.userInfo = res.data.data.user

            app.globalData.token = res.data.data.dy_token
            uni.setStorageSync('dy-token', res.data.data.dy_token)
            uni.setStorageSync('user_is_login', true)
            uni.setStorageSync('users', res.data.data.user)
            this.user_is_login = true

            // #ifdef APP || MP-WEIXIN || H5
            // 【请注意】这里的`uniIdToken` 是一个`对象`：包含：`token`和`tokenExpired`
            await uniImUtils.login({
              token: res.data.data.dy_uni_token,
              tokenExpired: res.data.data.dy_uni_token_expired
            })
            // #endif

            if (uni.getStorageSync('share_result_reg')) {
              uni.setStorageSync('share_result',true)
              uni.removeStorageSync('share_result_reg')
            }
            // #ifdef APP-PLUS || H5
            uni.preloadPage({url: "/ymq_canyino2o/pages/dyIm/imList/index"});
            // #endif

          }
        }
      });
    },
    toRegister() {
      let that = this
      console.log("share_user_id",uni.getStorageSync('share_user_id'))
      // this.loginParams.share_user_id=uni.getStorageSync('share_user_id')
      this.loginParams.share_user_id=3
      app.globalData.util.request({
        url: 'entry/wxapp/login_register_found_tel',
        no_token: true,
        data: {
          ...this.loginParams
        },
        success:  (res)=>{
          uni.showToast({
            title: res.data.msg
          });
          if (res.data.code==1){
            this.isFindPsd = false
            if (res.data.data.share_result) {
              //分享有礼注册成功,说明有礼物领取
              uni.setStorageSync('share_result_reg',true)
              uni.setStorageSync('share_money',res.data.data.share_money)
            }
          }
        }
      });
    },
    toSendMsg() {
      let that = this
      const {user_tel} = this.loginParams
      app.globalData.util.request({
        url: 'entry/wxapp/sms_code',
        no_token: true,
        data: {
          user_tel
        },
        success: function (res) {
          uni.showToast({
            title: res.data.msg
          });
          that.loginParams.sms_code = res.data.data.sms_code
        }
      });
    },
    toLogin() {
      this.isFindPsd = false
    },
    onFindPsdClick() {
      this.isFindPsd = true
    },
    toDownloadShop() {
      uni.navigateTo({
        url: '/ymq_canyino2o/pages/downloadShop/index'
      });
    },
    toDownload() {
      uni.navigateTo({
        url: '/ymq_canyino2o/pages/download/index'
      });
    },
    toJoin() {
      uni.navigateTo({
        url: '/ymq_canyino2o/pages/join/index'
      });
    },
    wdsc: function () {
      this.goToPageUrlUserLogin('../extra/wdsc')
    },

    wddd: function () {
      this.goToPageUrlUserLogin('../wddd/order')
    },

    wddz: function () {
      this.goToPageUrlUserLogin('../wddz/xzdz')
    },

    wdyy: function () {
      this.goToPageUrlUserLogin('../reserve/order')
    },

    wdqg: function () {
      this.goToPageUrlUserLogin('../xsqg/order')
    },

    wdpt: function () {
      this.goToPageUrlUserLogin('../collage/order')
    },

    wdyhq: function () {
      this.goToPageUrlUserLogin('../my/myyhq')
    },


    help: function () {
      uni.navigateTo({
        url: '../my/bzzx'
      });
    },

    seller: function () {
      if (this.user_is_login) {
        //用户登录成功了,则提示请先退出用户身份,再登录商家
        uni.showToast({
          title: '请先退出用户身份,再登录商家身份!',
          icon: 'none'
        })
        return
      }

      if (this.store_is_login) {
        //如果商家已登录,则直接跳转到商家中心
        // this.goToPageUrlReLaunch('/ymq_canyino2o/pages/sjzx/wmdd/wmdd')
        this.goToPageUrl('/ymq_canyino2o/pages/sjzx/wmdd/wmdd')
        return
      } else {
        this.goToPageUrl('/ymq_canyino2o/pages/sjzx/login')
        return
      }


      // var t = uni.getStorageSync('users').id;
      // app.globalData.util.request({
      // 	url: 'entry/wxapp/CheckRz',
      // 	cachetime: '0',
      // 	data: {
      // 		user_id: t
      // 	},
      // 	success: function(t) {
      // 		console.log(t.data);
      // 		if (0 != t.data) {
      // 			if (1 == t.data.state) {
      // 				uni.showModal({
      // 					title: '',
      // 					content: '系统正在审核中'
      // 				});
      // 			} else {
      // 				if (2 == t.data.state) {
      // 					uni.setStorageSync('sjdsjid', t.data.id);
      // 					uni.navigateTo({
      // 						url: '../sjzx/wmdd/wmdd'
      // 					});
      // 				} else {
      // 					if (3 == t.data.state) {
      // 						uni.showModal({
      // 							title: '',
      // 							content: '您的合作申请已被拒绝，点击确定进行编辑',
      // 							success: function(t) {
      // 								if (t.confirm) {
      // 									uni.navigateTo({
      // 										url: '../ruzhu/index?state=3'
      // 									});
      // 								}
      // 							}
      // 						});
      // 					} else {
      // 						uni.showModal({
      // 							title: '',
      // 							content: '您的合作已经到期,请联系平台管理员续费'
      // 						});
      // 					}
      // 				}
      // 			}
      // 		} else {
      // 			uni.navigateTo({
      // 				url: '../sjzx/login'
      // 			});
      // 		}
      // 	}
      // });

    },

    fx: function () {
      this.goToPageUrlLogin('../distribution/index')
    },

    jfsc: function () {
      this.goToPageUrlLogin('../integral/integral')
    },

    czzx: function () {
      this.goToPageUrlLogin('../wallet/walletadd')
    },

    tzhy: function () {
      this.goToPageUrlLogin('../hyk/hyk')
    },
    onModalClose() {
      this.isShowModal = false;
    },
    onModalOpen() {
    },
    onLoginClick() {
      this.isShowModal = true;
      // let that = this;
      // app.globalData.util.request({
      // 	url: 'entry/wxapp/login',
      // 	cachetime: '0',
      // 	data: {
      // 		xxxx: '1111'
      // 	},
      // 	dataType: 'json',
      // 	success: function(t) {
      // 		app.globalData.userInfo = t.data;
      // 		console.log('用户信息', t);
      // 	}
      // });
    },
    changeData: function () {
      var that = this;
      uni.getUserProfile({
        desc: '用于完善会员资料',
        success: res => {
          app.globalData.util.request({
            url: 'entry/wxapp/login',
            cachetime: '0',
            data: {
              openid: getApp().globalData.getOpenId,
              img: res.userInfo.avatarUrl,
              name: res.userInfo.nickName
            },
            header: {
              'content-type': 'application/json'
            },
            dataType: 'json',
            success: function (t) {
              app.globalData.userInfo = t.data;
              console.log('用户信息', t);
            }
          });
          var userInfo = that.userInfo;
          userInfo.img = res.userInfo.avatarUrl;
          userInfo.user_name = res.userInfo.nickName;
          userInfo.name = res.userInfo.nickName;
          that.setData({
            userInfo: userInfo,
            avatarUrl: res.userInfo.avatarUrl,
            nickName: res.userInfo.nickName
          });
        }
      });
    },

    jumps: function (t) {
      var e = t.currentTarget.dataset.id;
      var a = t.currentTarget.dataset.name;
      var n = t.currentTarget.dataset.appid;
      var o = t.currentTarget.dataset.src;
      var s = t.currentTarget.dataset.wb_src;
      var i = t.currentTarget.dataset.type;
      console.log(e, a, n, o, s, i);
      if (1 == i) {
        console.log(o);
        uni.navigateTo({
          url: o
        });
      } else {
        if (2 == i) {
          uni.setStorageSync('vr', s);
          uni.navigateTo({
            url: '../car/car'
          });
        } else {
          if (3 == i) {
            uni.navigateToMiniProgram({
              appId: n
            });
          }
        }
      }
    },

    feedback: function (t) {
      uni.navigateTo({
        url: 'feedback'
      });
    },

    wallet: function (t) {
      uni.navigateTo({
        url: '../wallet/wallet'
      });
    },

    set_up: function (t) {
      uni.navigateTo({
        url: 'set_up'
      });
    },

    receive: function (t) {
      uni.navigateTo({
        url: 'receive'
      });
    },

    integral: function (t) {
      uni.navigateTo({
        url: '../integral/myintegral'
      });
    },

    sign_in: function (t) {
      uni.navigateTo({
        url: 'rankings'
      });
    },

    sjrz: function (t) {
      var e = uni.getStorageSync('users').id;
      app.globalData.util.request({
        url: 'entry/wxapp/CheckRz',
        cachetime: '0',
        data: {
          user_id: e
        },
        success: function (t) {
          console.log(t.data);
          if (0 != t.data) {
            if (1 == t.data.state) {
              uni.showModal({
                title: '',
                content: '系统正在审核中'
              });
            } else {
              if (2 == t.data.state) {
                uni.showModal({
                  title: '',
                  content: '您已经合作过了'
                });
              } else {
                if (3 == t.data.state) {
                  uni.showModal({
                    title: '',
                    content: '您的合作申请已被拒绝，点击确定进行编辑',
                    success: function (t) {
                      if (t.confirm) {
                        uni.navigateTo({
                          url: '../ruzhu/index?state=3'
                        });
                      }
                    }
                  });
                } else {
                  uni.showModal({
                    title: '',
                    content: '您的合作已经到期,请联系平台管理员续费'
                  });
                }
              }
            }
          } else {
            uni.navigateTo({
              url: '../ruzhu/index'
            });
          }
        }
      });
    }
  }
};
</script>
<style>
@import './index.css';
</style>
<style scoped>
.tabs {
  display: flex;
  align-items: center;
  margin-bottom: 40rpx;
}

.tabs .tab-item {
  margin-right: 40rpx;
}

.tabs .tab-item.active {
  font-weight: 600;
}

.register {
  width: 100%;
  margin-top: 40rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
</style>
